package com.qianfeng.smartdevice.service.impl;

import com.qianfeng.smartdevice.mapper.SysMenuMapper;
import com.qianfeng.smartdevice.pojo.SysMenu;
import com.qianfeng.smartdevice.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by wenka on 2022/3/26 14:20
 *
 * @author wenka
 * @version 1.0
 * @since 1.0
 */
@Service
@Transactional
public class SysMenuServiceImpl implements SysMenuService {
    private SysMenuMapper sysMenuMapper;

    @Autowired
    public void setSysMenuMapper(SysMenuMapper sysMenuMapper) {
        this.sysMenuMapper = sysMenuMapper;
    }

    @Override
    public List<SysMenu> findAllMenu() {
        return sysMenuMapper.findAllMenu();
    }

    @Override
    public List<SysMenu> findAllLeftMenu() {
        List<SysMenu> allMenu = findAllMenu();
        //过滤收集左侧菜单
        List<SysMenu> menuList = allMenu.stream().filter(sysMenu -> {
            return sysMenu.getMenuType().equalsIgnoreCase("M") && !"#".equalsIgnoreCase(sysMenu.getUrl());
        }).collect(Collectors.toList());
        return menuList;
    }
}
